<?php  
 // session_start();

          if(!empty($_POST)){
          
                //$_POST的所有数据存储在临时变量中
                  $name=$_POST['name'];
                  $pid=$_POST['pid'];
                 
//编写插入语句 
$sql = "insert into `cate`(`name`,`pid`)values('$name','$pid')";
//编写执行语句
mysqli_query($link,$sql);
//mysqli_affected_rows($link)语句可以检测语句是否执行成功
  $_rows=mysqli_affected_rows($link);

//如果$_rows>0说明成功
if ($_rows>0) {
    echo '<script> alert ("新闻数据添加成功");location.href="index.php?c=cate&a=list&admin=1";</script>';die;
       
}else{

    echo '<script> alert ("新闻数据添加失败");history.go(-1);</script>';
        die;
}


}
  
 $id = empty($_GET['id'])?0:$_GET['id'];
  // 顶级分类显示
 $sql = "select * from `cate` where pid=$id ";
 // echo $sql;die;
 $result = mysqli_query($link,$sql);

 while ($arr = mysqli_fetch_assoc($result)) {
     $cate[] =$arr;
 }

         // 判断ajax请求
   if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

           echo json_encode($cate);die;


   }






//链接news.html的语句
include (VIEW_PATH.$admin.'/layout.html');

?>

